package com.example.user.controller;

import com.example.common.api.ResultUtil;
import com.example.common.validator.Insert;
import com.example.user.model.vo.RoleVO;
import com.example.user.service.IRoleService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/role")
@Validated
public class RoleController {

    @Resource
    private IRoleService roleService;

    @RequestMapping(value = "/create_role", method = RequestMethod.PUT)
    @ResponseBody
    public ResultUtil createRole(@RequestBody @Validated(Insert.class) RoleVO roleVO){
        return roleService.createRole(roleVO);
    }

    @RequestMapping(value = "/update_role_status", method = RequestMethod.POST)
    @ResponseBody
    public ResultUtil updateRoleStatus(@NotNull(message = "角色ID不能为空") @RequestParam("roleId") Long roleId,
                                       @NotNull(message = "修改状态不能为空")@RequestParam("status") int status){
        return roleService.updateRoleStatus(roleId, status);
    }
}
